<?php
class Photo_model extends CI_Model {
	
	var $photo_path;
	var $photo_path_url;
	
	function __construct(){
		// Call the Model constructor
		parent::__construct();
		$this->photo_path = realpath(APPPATH. '../assets/uploads');
		$this->photo_path_url = base_url(). 'assets/uploads';
	}
	//upload
	function do_upload(){
		//foreach($updload_files as $field => $updload_file)
		/**$updload_files = array(
        'userfile1' => $_FILES['userfile1'],
        'userfile2' => $_FILES['userfile2'],
        // You can add more
        );**/
		
		$conifg = array(
				'allowed_type' => 'jpg|jpeg|gif|png',
				'upload_path' => $this->photo_path,
				'max_size' => 2000
				);
		$this->load->library('upload', $config);
		$this->upload->do_upload();
		$image_data = $this->upload->data();
		
		$config = array(
				'source_image' => $image_data['full_path'],
				'new_image' => $this->photo_path . '/thumbs',
				'maintain_ration' => true,
				'width' => 150,
				'height' => 100
				);
		
		$this->load->library('image_lib', $config);
		$this->image_lib->resize();
	}
	//get image
	function get_images(){
		$files = scandir($this->gallery_path);
		$files = array_diff($files, array('.', '..', 'thumbs'));
		
		$images = array();
		foreach($files as $file){
			$images[] = array(
					'url' => $this->photo_path_url . $file,
					'thumb_url' => $this->photo_path_url . '/thumbs' . $file
					);
		}
	}
}
?>